<?php

namespace mpend\modules\share\models;

use Yii;
use common\helpers\Url;
use yii\helpers\ArrayHelper;

/**
 * 邀请详情
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class ShareInviteView extends \common\models\workbook\WorkbookInvite {

    /**
     * @inheritdoc
     */
    public function getWorkbook() {
        return $this->hasOne(ShareBookView::class, ['id' => 'workbook_id']);
    }

    public function getInviteData() {
        return [
            'icon' => '/static/icons/quote.png',
            'content' => $this->description,
            'expiredTime',
            'action' => $this->action,
        ];
    }

    public function getOwn() {
        if ($this->user_id !== Yii::$app->user->id) {
            return null;
        }
        return [
            'title' => '工人邀请中',
            'description' => '最近1小时共0人加入记工薄',
            
            'action' => [
                'text' => '结束邀请',
                'color' => 'linear-gradient(to right, #4bb0ff, #6149f6)',
                'confirm' => [
                    'message' => '关闭后，接收到分享邀请的人将不可再通过邀请进入记工薄，是否继续操作？',
                    'request' => [
                        'method' => 'post',
                        'params' => [],
                        'url' => Url::to(['/share/invite/delete', 'id' => $this->id])
                    ],
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'workbook',
            'user',
            'invite' => 'inviteData',
            'icon' => function() {
                return '/static/icons/quote.png';
            },
            'content' => 'description',
            'type',
            'expiredTime',
            'action',
            'own',
            'isActive',
            'shareData',
        ];
    }

}
